import java.util.Arrays;
import java.util.Scanner;

public class IPZW {
    /**
     * 判断两个IP是否属于同一子网
     * @param args
     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()){
            String a = scanner.nextLine();
            String b = scanner.nextLine();
            String c = scanner.nextLine();

            String[] aa=a.split("\\.");
            String[] bb=b.split("\\.");
            String[] cc=c.split("\\.");

            int[] aaa = Arrays.stream(aa).mapToInt(Integer::parseInt).toArray();
            int[] bbb = Arrays.stream(bb).mapToInt(Integer::parseInt).toArray();
            int[] ccc = Arrays.stream(cc).mapToInt(Integer::parseInt).toArray();

            if(!isIP(bbb) || !isIP(ccc) || !isMask(aaa)){
                System.out.println(1);
                continue;
            }

            boolean flag = true;

            for (int i = 0; i < 4; i++) {
                if((bbb[i] & aaa[i]) != (ccc[i] & aaa[i])){
                    System.out.println(2);
                    flag = false;
                    break;
                }

            }

            if(flag){
                System.out.println(0);
            }

        }



    }

    private static boolean isMask(int[] a) {
        return a[0] >= 0 && a[0] <= 255 &&
                a[1] >= 0 && a[1] <= 255 &&
                a[2] >= 0 && a[2] <= 255 &&
                a[3] >= 0 && a[3] <= 255 &&
                a[0] >= a[1] && a[1] >= a[2] && a[2] >= a[3];
    }

    private static boolean isIP(int[] a) {
        return a[0] >= 0 && a[0] <= 255 &&
                a[1] >= 0 && a[1] <= 255 &&
                a[2] >= 0 && a[2] <= 255 &&
                a[3] >= 0 && a[3] <= 255;

    }
}
